package com.itheima;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * @Author：shenkunlin
 * @date： 2021/8/20 10:50
 * @Description：
 ***/
@SpringBootApplication
@MapperScan(basePackages = "com.itheima.article.mapper")
@EnableFeignClients(basePackages = "com.itheima.*.feign")
//创建代理数据源
@EnableAutoDataSourceProxy
public class AritcleApplication {

    public static void main(String[] args) {
        SpringApplication.run(AritcleApplication.class,args);
    }

    /***
     * 全局类型转换器
     *      将Long类型转换成String类型输出
     * 缺陷：所有Long类型都会转换成String输出
     * @return
     */
    //@Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer(){
        return new Jackson2ObjectMapperBuilderCustomizer() {
            @Override
            public void customize(Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder) {
                //把long类型转换成字符串类型
                jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
            }
        };
    }
}
